package com.ts.api.http.market.channel;

import com.gitee.apanlh.util.base.MapUtils;
import com.gitee.apanlh.web.model.vo.RequestVO;
import com.ts.api.module.api.convert.core.annotation.ApiChannelMarket;
import com.ts.api.module.api.convert.core.annotation.ApiChannelMarketConvertType;
import com.ts.api.module.api.convert.core.entity.ApiBizStatus;
import com.ts.api.module.api.convert.market.entity.ChannelMarketParameter;
import com.ts.api.module.api.convert.market.handler.ChannelMarketConvertHandler;
import com.ts.api.module.api.entity.ApiUserRequest;

import java.util.Map;

/**
 *  测试类(命名得去掉下划线)
 *  UV-前置MD5撞库接口
 *
 *  @author Pan
 */
@ApiChannelMarket(uniqueCode = "54a5e8e32d1a4f36b8abe9d3053911d2", type = ApiChannelMarketConvertType.DATA_EXCHANGE_MD5)
public class xxxxMd5Test implements ChannelMarketConvertHandler {

    @Override
    public ApiUserRequest parse(RequestVO requestVO) {
        ApiUserRequest apiUserRequest = new ApiUserRequest();
        String phone = requestVO.getStr("phoneMd5");
        apiUserRequest.setPhoneMd5(phone);
        return apiUserRequest;
    }

    @Override
    public Map<String, Object> response(ChannelMarketParameter channelMarketParameter, ApiBizStatus apiBizStatus) {
        if (apiBizStatus.hasBizSuc()) {
            return MapUtils.newHashMap(newMap -> {
                Map<String, Object> result = MapUtils.newHashMap(data -> {
                    data.put("code", 0);
                    data.put("msg", apiBizStatus.getBizMsg());
                });
                newMap.put("data", result);
            });
        }

        return MapUtils.newHashMap(newMap -> {
            Map<String, Object> result = MapUtils.newHashMap(data -> {
                data.put("code", 1);
                data.put("msg", apiBizStatus.getBizMsg());
            });
            newMap.put("data", result);
        });
    }
}
